#include <iostream>
#include <functional>

class int_processor : public std::unary_function<int, void> {
	const int min_;
	const int max_;
	bool& triggered_;

public:
	int_processor(int min, int max, bool& triggered)
		: min_(min), max_(max), triggered_(triggered)
	{}

	void operator()(int i) const {
		if (i < min_ || i > max_) {
			triggered_ = true;
		}
	}

	~int_processor()
	{
		std::cout << "~int_processor" << std::endl;
	}
};

typedef std::function<void(int)> fobject_t;

void process_integers(const fobject_t& f)
{
	f(300);
}

bool g_is_triggered = false;

void set_functional_object(fobject_t& f) {
	int_processor fo(100, 200, g_is_triggered);
	// f = fo;
	std::cout << "set_functional_object" << std::endl;
}

int main()
{
	/*bool is_triggered = false;
	int_processor fo(0, 200, is_triggered);
	process_integers(fo);
	std::cout << "==== 1 ====" << std::endl
		<< std::boolalpha << "is_triggered:" << is_triggered << std::endl;

	std::cout << "==== 2 ====" << std::endl;
	process_integers(
		[](int i)
		{
			std::cout << "i:" << i << std::endl;
		}
	);*/

	fobject_t f1;
	set_functional_object(f1);
	std::cout << "set_functional_object(f1) end" << std::endl;
	// f1(300);
	//std::cout << "==== 3 ====" << std::endl
	//	<< std::boolalpha << "g_is_triggered:" << g_is_triggered << std::endl;
	return 0;
}